package com.geekbang.homework.WeekOneHomework;

public class MoveZeroes {
    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};

        int[] result = moveZeroes(nums);
        for (int j : result) {
            System.out.print(j);
            System.out.print(",");
        }
    }

    public static int[] moveZeroes(int[] nums) {
        int j = 0;
        for(int i = 0; i < nums.length; ++i){
            if(nums[i] != 0){
                nums[j] = nums[i];
                if(i != j){
                    nums[i] = 0;
                }
                j++;
            }
        }
        return nums;
    }
}
